package net.neptech.controller;

import net.neptech.model.information.InforArticle;
import net.neptech.service.InforArticleService;
import net.neptech.vm.ResponseResult;
import org.apache.ibatis.plugin.Interceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 谢辉
 * @Date 2025/8/21 9:57
 * @Description 健康科普文章三层架构
 **/

@RestController
@RequestMapping("information/article")
public class InforArticleController {

    @Autowired
    InforArticleService inforArticleService;

    /**
     * 新增文章
     */
    @PostMapping("addArticle")
    public ResponseResult addArticle(@RequestBody InforArticle inforArticle){
        inforArticleService.addArticle(inforArticle);
        return ResponseResult.success();
    }

    /**
     * 删除文章
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteArticle(@PathVariable("id") Long id){
        inforArticleService.deleteArticle(id);
        return ResponseResult.success();
    }

    /**
     * 查询全部文章
     */
    @GetMapping()
    public ResponseResult findArticle(){
        return ResponseResult.success(inforArticleService.findArticle());
    }

    /**
     * 修改文章
     */
    @PutMapping("updateArticle")
    public ResponseResult updateArticle(@RequestBody InforArticle inforArticle){
        inforArticleService.updateArticle(inforArticle);
        return ResponseResult.success();
    }

    /**
     * 根据id查询文章
     */
    @GetMapping("/{id}")
    public ResponseResult findArticleById(@PathVariable("id") Long id) {
        return ResponseResult.success(inforArticleService.findArticleById(id));
    }
}
